<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>let变量声明</title>
</head>
<body>
    <script>
        // 声明变量
        let a;
        let b,c,d;
        let e = 100;
        let f = 200, g = 'ii', h = [];

        // 1. 变量不能重复声明
        let s = '喵';
        // let s = '汪'; // Uncaught SyntaxError: Identifier 's' has already been declared

        // 2. 作用域：块级、全局、函数、eval
        // if elseif else for while
        {
            let x = 'X';
            //var x = 'X';
        }
        // console.log('x: ', x); // Uncaught ReferenceError: x is not defined

        // 3. 不存在变量提升
        // console.log(y);
        // var y = 'Y';
        // let y = 'Y'; // Uncaught ReferenceError: Cannot access 'y' before initialization

        // 4. 不影响作用链
        {
            let m = 'link';
            function fun() {
                console.log(m);
            }
            fun();
        }

    </script>
</body>
</html>